package com.jiangyao.controller;

import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.backend.SubjectChapterDTO;
import com.jiangyao.model.dto.backend.SubjectChapterDelDTO;
import com.jiangyao.model.dto.backend.SubjectDTO;
import com.jiangyao.model.dto.backend.SubjectListPageDTO;
import com.jiangyao.model.vo.backend.SubjectChapterVO;
import com.jiangyao.model.vo.backend.SubjectDetailVO;
import com.jiangyao.model.vo.backend.SubjectListVO;
import com.jiangyao.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author yangyongchuan
 * @since 2020-08-19
 */
@RestController
@RequestMapping("/subject")
@Api(tags = "课程管理")
public class SubjectController extends BaseController {

	@Autowired
	private SubjectService subjectService;

	/**
	 * 获取课程列表
	 *
	 * @param listPageDTO 列表DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取课程列表")
	@PostMapping("/list")
	public ApiResult<SubjectListVO> getListPage(@Validated({SubjectListPageDTO.ListPage.class}) @RequestBody SubjectListPageDTO listPageDTO) {
		return ApiResult.success(subjectService.getListPage(listPageDTO));
	}

	/**
	 * 增加课程
	 *
	 * @param subjectDTO 增加DTO
	 * @return 结果
	 */
	@ApiOperation(value = "增加课程")
	@PostMapping("/add")
	public ApiResult<String> add(@Validated({SubjectDTO.Add.class}) @RequestBody SubjectDTO subjectDTO) {
		subjectService.add(subjectDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 编辑课程
	 *
	 * @param subjectDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑课程")
	@PostMapping("/edit")
	public ApiResult<String> edit(@Validated({SubjectDTO.Edit.class}) @RequestBody SubjectDTO subjectDTO) {
		subjectService.edit(subjectDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 编辑课程状态（启用、禁用）
	 *
	 * @param subjectDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑课程状态（启用、禁用）", notes = "必填字段：subjectIdList、status")
	@PostMapping("/editStatus")
	public ApiResult<String> editStatus(@Validated({SubjectDTO.Delete.class}) @RequestBody SubjectDTO subjectDTO) {
		subjectService.editStatus(subjectDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 更新是否精选 0-否 1-是
	 *
	 * @param subjectDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "是否精选 0-否 1-是", notes = "必填字段：subjectIdList、isChoiceness")
	@PostMapping("/editSubjectChoiceness")
	public ApiResult<String> editSubjectChoiceness(@Validated({SubjectDTO.Delete.class}) @RequestBody SubjectDTO subjectDTO) {
		subjectService.editChoiceness(subjectDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 更新公开课状态 0-不是 1-是公开课
	 *
	 * @param subjectDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "更新公开课状态 0-不是 1-是公开课", notes = "必填字段：subjectIdList、isPublic")
	@PostMapping("/editSubjectPublicStatus")
	public ApiResult<String> editSubjectPublicStatus(@Validated({SubjectDTO.Delete.class}) @RequestBody SubjectDTO subjectDTO) {
		subjectService.editPublicStatus(subjectDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 获取课程详情
	 *
	 * @param subjectDTO 请求DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取课程详情", notes = "必填字段：subjectId")
	@PostMapping("/detail")
	public ApiResult<SubjectDetailVO> detail(@Validated({SubjectDTO.Detail.class}) @RequestBody SubjectDTO subjectDTO) {
		return new ApiResult<>(subjectService.getDetail(subjectDTO));
	}

	/**
	 * 获取课程章节列表
	 *
	 * @param subjectDTO 请求DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取课程章节列表", notes = "必填字段：subjectId")
	@PostMapping("/chapter/list")
	public ApiResult<SubjectChapterVO> getChapterList(@Validated({SubjectDTO.Detail.class}) @RequestBody SubjectDTO subjectDTO) {
		return new ApiResult<>(subjectService.getChapterList(subjectDTO));
	}

	/**
	 * 编辑课程章节
	 *
	 * @param subjectChapterDTO 课程章节DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑课程章节")
	@PostMapping("/chapter/update")
	public ApiResult<String> updateChapter(@Validated({SubjectChapterDTO.Edit.class}) @RequestBody SubjectChapterDTO subjectChapterDTO) {
		subjectService.updateChapter(subjectChapterDTO);
		return new ApiResult<>();
	}

	/**
	 * 删除课程章节、章节课件
	 *
	 * @param delDTO 删除课程章节DTO
	 * @return 结果
	 */
	@ApiOperation(value = "删除课程章节、章节课件", notes = "必填字段：subjectId；（chapterId、chcoId二选一）")
	@PostMapping("/chapter/delete")
	public ApiResult<String> deleteChapter(@Validated({SubjectChapterDelDTO.Delete.class}) @RequestBody SubjectChapterDelDTO delDTO) {
		subjectService.deleteChapter(delDTO);
		return new ApiResult<>();
	}

}

